package C622;

/**
 * @program: javase
 * @description:
 * @author: luolidong
 * @create: 2021-06-22 15:35
 * @version: 1.0
 */
public class ThreadTest {
    volatile static boolean flag=false;
    public static void main(String[] args) {
        MyThread a=new MyThread();
//            while (!flag){
//                System.out.println(111);
//            }
//            使用a.isInterrupted()判断是否有中断标记

        a.start();
        Thread b = new Thread(() -> {
            System.out.println(2);
        }, "B");
        //并不是调用b线程的sleep方法，并且b还没有开启
//        b.sleep(3000);
        try {
            Thread.sleep(1000);
//            flag=true;
            //interrupt()并不能让线程真正中断，而是设置中断标记
            a.interrupt();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        b.start();
    }
}
class MyThread extends Thread{

    @Override
    public void run() {
        while (!this.isInterrupted()){
            System.out.println(111);
        }
    }
}
